<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>main</title>
    <link rel="stylesheet" type="text/css" href="{{$smarty.const.JS}}layui/css/layui.css" />
    <style type="text/css">
        form{margin-top: 20px;}
    </style>
    <!-- <script type="text/javascript" src="{{$smarty.const.JS}}forbidRight.js"></script> -->
</head>
<body>
    <form class="layui-form" action="">
        {{if $smarty.get.act == "edit"}} <input type="hidden" name="id" value="{{$list.id}}">{{/if}}
        {{if $smarty.get.act == "edit"}} 
            <input type="hidden" name="pid" value="{{$list.pid}}">
        {{else if $smarty.get.act == "add"}} 
            {{if  isset($smarty.get.id)}}
                <input type="hidden" name="pid" value="{{$smarty.get.id}}">
            {{else}}
                <input type="hidden" name="pid" value="0">
            {{/if}}
        {{/if}}
        <div class="layui-form-item">
            <label class="layui-form-label">分类名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input" style="width: 60%;" {{if $smarty.get.act == "edit"}} value="{{$list.name}}"{{/if}}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="sort" lay-verify="title" autocomplete="off" placeholder="请输入序号" class="layui-input" style="width: 60%;" {{if $smarty.get.act == "edit"}} value="{{$list.sort}}"{{/if}}>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
            {{if $smarty.get.act=="add"}}
                <button class="layui-btn" lay-submit="" lay-filter="add">添加</button>
            {{else if $smarty.get.act=="edit"}}
                <button class="layui-btn" lay-submit="" lay-filter="edit">确认修改</button>
            {{/if}}
            </div>
        </div>
    </form>
</body>
<script src="{{$smarty.const.JS}}jquery.min.js" charset="utf-8"></script>
<script src="{{$smarty.const.JS}}layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(add)', function(data){
            $.ajax({
                url:'add',
                data:data.field,
                type:'post',
                dataType:'json',
                success:function(redata){
                    if (redata.msg == 1) {
                        window.parent.location.reload();//刷新父页面
                        layer.closeAll('iframe');//关闭弹窗
                    }else{
                        layer.alert("添加失败，请重试！");
                    }
                }
            });
            return false;
        });
        form.on('submit(edit)', function(data){
            $.ajax({
                url:'edit',
                data:data.field,
                type:'post',
                dataType:'json',
                success:function(redata){
                    if (redata.msg == 1) {
                        window.parent.location.reload();//刷新父页面
                        layer.closeAll('iframe');//关闭弹窗
                    }else{
                        layer.alert("修改失败，请重试！");
                    }
                }
            });
            return false;
        });
    });
</script>
</html>